/*
 * @Author: your name
 * @Date: 2021-07-07 11:41:49
 * @LastEditTime: 2021-07-21 13:54:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \cuiyuan_activity\assets\script\SwiperItem.ts
 */
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html


import NavBar from "./NavBar";
import SceneContent from "./ContentScene";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NavItem extends cc.Component {

    @property(cc.Sprite)
    thumb: cc.Sprite = null;
    @property(cc.Label)
    title: cc.Label = null;


    // 图集资源
    @property(cc.SpriteAtlas)
    thumbs: cc.SpriteAtlas = null
    @property(cc.Node)
    mask: cc.Node = null;
    @property(cc.SpriteFrame)
    lock_bg: cc.SpriteFrame = null;
    @property(cc.SpriteFrame)
    active_bg: cc.SpriteFrame = null

    id: number;
    isActive: boolean = false;

    static inst: NavItem;




    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        NavItem.inst = this;
    }

    /**
     * 
     * @param thumb 图集资源对应的图片
     * @param title 标题
     * @param id id
     */
    init(thumb: string, title: string, id: number) {
        this.title.string = title;
        this.id = id;
        // 获取图集 修改当前展示图集
        this.thumb.spriteFrame = this.thumbs.getSpriteFrame(thumb)
        if (SceneContent.inst.currentIndex >= id) {
            this.unLock();
        }
    }

    // 设置当前激活状态
    setActive() {
        this.isActive = true;
        this.mask.active = true;
        this.mask.getComponent(cc.Sprite).spriteFrame = this.active_bg;
    }

    // 设置当前为未激活
    setNormal() {
        this.isActive = false;
        this.mask.active = true;
        this.mask.getComponent(cc.Sprite).spriteFrame = this.lock_bg;
    }

    // 解锁
    unLock() {
        this.mask.active = false;
    }

    // 点击后，改变主场景展示的内容
    changeScene() {
        if (SceneContent.inst.totalIndex < this.id) {
            return NavBar.inst.showNotice()
        };
        SceneContent.inst.changePlayNode(this.id);
    }

    start() {

    }

    // update (dt) {}
}
